#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int replaceNum(string num, char src, char dst)
    {
        for (auto& c : num)
        {
            if (c == src)
                c = dst;
        }
        return stoi(num);
    }
    int maxDiff(int num) {
        string str_a = to_string(num), str_b = to_string(num);
        int a = num, b = num;
        for (auto e : str_a)
        {
            if (e != '9')
            {
                a = replaceNum(str_a, e, '9');
                break;
            }
        }
        for (auto e : str_b)
        {
            if (e != str_b[0] && e != '0')
            {
                b = replaceNum(str_b, e, '0');
                break;
            }
            else if (e == str_b[0] && e != '1')
            {
                b = replaceNum(str_b, e, '1');
                break;
            }
        }
        return a - b;
    }
};